/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BoothManagement.java
 *
 * Created on Aug 11, 2010, 2:56:54 PM
 */

package Gui;

import BusinessLogic.BoothManagement;
import BusinessLogic.DateUtility;
import DTO.Zone;
import java.awt.Color;
import java.awt.Dimension;
import java.util.Calendar;
import java.util.Vector;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;

/**
 *
 * @author Administrator
 */
public class pnBooth extends javax.swing.JPanel {

    private BoothManagement BoothMag;
    private Vector<Zone> listZone;
    private JCheckBox[] cbZone;
    private JRadioButton[] rdDate;

    /** Creates new form BoothManagement */
    public pnBooth() {
        initComponents();
        //Create object Booth management
        BoothMag = new BoothManagement();
        //load listZone
        listZone = BoothMag.loadZone();
        //initial option zone and date
        initZoneNDate();
    }

    public void initZoneNDate(){
        //get leng of listZone
        int numberZone = listZone.size();
        //if numberzone > 4, set pnDatenZone scroll
        if(numberZone > 4){
            pnDatenZone.setPreferredSize(new Dimension(400, numberZone * 30));
        }
        
        //initial array checkbox
        cbZone = new JCheckBox[numberZone];
        for(int i = 0; i < numberZone; i++){
            Zone zone = listZone.get(i);

            String str = zone.getName().toUpperCase() + " - Size: " + zone.getSize() + " - Money: " + zone.getMoney();
            cbZone[i] = new JCheckBox(str, true);
            pnDatenZone.add(cbZone[i]);
            cbZone[i].setBounds(50, 25*i, 200, 25);
            cbZone[i].setBackground(Color.WHITE);
        }

        rdDate = new JRadioButton[4];
        for(int i = 0; i < 4; i++){
            rdDate[i] = new JRadioButton();
            rdGroupDate.add(rdDate[i]);
            pnDatenZone.add(rdDate[i]);
            rdDate[i].setBounds(320, 25*i, 100, 25);
            rdDate[i].setBackground(Color.WHITE);
        }
        rdDate[0].setSelected(true);
        rdDate[0].setText("All day");
        rdDate[1].setText("2 days ago");
        rdDate[2].setText("4 days ago");
        rdDate[3].setText("6 days ago");
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rdGroupDate = new javax.swing.ButtonGroup();
        pnExhibi = new javax.swing.JPanel();
        lbSource = new javax.swing.JLabel();
        lblBoothMag = new javax.swing.JLabel();
        pnExhibi1 = new javax.swing.JPanel();
        lblReadReport = new javax.swing.JLabel();
        lbSource1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        pnDatenZone = new javax.swing.JPanel();
        pnExhibi2 = new javax.swing.JPanel();
        lbSource2 = new javax.swing.JLabel();
        lblViewChart = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setLayout(null);

        pnExhibi.setBackground(new java.awt.Color(255, 255, 255));
        pnExhibi.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Booth Management", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        pnExhibi.setLayout(null);

        lbSource.setText("<html>\n View all information of booth. Can insert, update, delete booth<br>\n Input:  Information of Booth, id of Exhibitor and select a zone. Fees and service was compute belong with this.<br>\n<b>Notes:</b><br>\nWhen change information of Booth, System automatically updates exhibitor accounts\n</html>");
        pnExhibi.add(lbSource);
        lbSource.setBounds(30, 20, 480, 80);

        lblBoothMag.setBackground(new java.awt.Color(255, 255, 255));
        lblBoothMag.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblBoothMag.setForeground(new java.awt.Color(0, 70, 213));
        lblBoothMag.setText("<html> <u>Booth Management</u> </html>");
        lblBoothMag.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                lblBoothMagMousePressed(evt);
            }
        });
        pnExhibi.add(lblBoothMag);
        lblBoothMag.setBounds(400, 100, 150, 20);

        add(pnExhibi);
        pnExhibi.setBounds(20, 20, 560, 130);

        pnExhibi1.setBackground(new java.awt.Color(255, 255, 255));
        pnExhibi1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Report about Booth", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        pnExhibi1.setLayout(null);

        lblReadReport.setBackground(new java.awt.Color(255, 255, 255));
        lblReadReport.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblReadReport.setForeground(new java.awt.Color(0, 70, 213));
        lblReadReport.setText("<html>\n<u>Read Report</u>\n</html>");
        lblReadReport.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                lblReadReportMousePressed(evt);
            }
        });
        pnExhibi1.add(lblReadReport);
        lblReadReport.setBounds(230, 150, 80, 30);

        lbSource1.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbSource1.setText("Please choose Zones and date to create report.");
        pnExhibi1.add(lbSource1);
        lbSource1.setBounds(30, 20, 320, 30);

        jScrollPane1.setBorder(null);

        pnDatenZone.setBackground(new java.awt.Color(255, 255, 255));
        pnDatenZone.setLayout(null);
        jScrollPane1.setViewportView(pnDatenZone);

        pnExhibi1.add(jScrollPane1);
        jScrollPane1.setBounds(40, 50, 480, 110);

        add(pnExhibi1);
        pnExhibi1.setBounds(20, 250, 560, 180);

        pnExhibi2.setBackground(new java.awt.Color(255, 255, 255));
        pnExhibi2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Chart and Graphic", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        pnExhibi2.setLayout(null);

        lbSource2.setText("<html>\n View charts and graphs for the Executive Director/Board\n</html>");
        pnExhibi2.add(lbSource2);
        lbSource2.setBounds(30, 20, 390, 30);

        lblViewChart.setBackground(new java.awt.Color(255, 255, 255));
        lblViewChart.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblViewChart.setForeground(new java.awt.Color(0, 70, 213));
        lblViewChart.setText("<html> <u>View Chart</u> </html>");
        lblViewChart.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                lblViewChartMousePressed(evt);
            }
        });
        pnExhibi2.add(lblViewChart);
        lblViewChart.setBounds(450, 50, 90, 20);

        add(pnExhibi2);
        pnExhibi2.setBounds(20, 160, 560, 80);

        getAccessibleContext().setAccessibleParent(this);
    }// </editor-fold>//GEN-END:initComponents

    private void lblBoothMagMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblBoothMagMousePressed
        // TODO add your handling code here:
        DLBooth bo = new DLBooth(null, true);
        bo.setVisible(true);
}//GEN-LAST:event_lblBoothMagMousePressed

    private void lblReadReportMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblReadReportMousePressed
        // TODO add your handling code here:
        Vector<Zone> subList = new Vector<Zone>();
        int day = 0;
        String date = "";
        
        for(int i = 0; i < listZone.size(); i++){
            Zone zone = listZone.get(i);
            if(cbZone[i].isSelected()){
                subList.add(zone);
            }
        }
        //check date
        if(rdDate[0].isSelected()){
            day = 100;
        } else if(rdDate[1].isSelected()){
            day = 2;
        } else if(rdDate[2].isSelected()){
            day = 4;
        } else if(rdDate[3].isSelected()){
            day = 6;
        }
        Calendar cal = Calendar.getInstance();
        date = DateUtility.subToDate(cal, day);
        //export report
        BoothMag.printReport(subList, date);
        
    }//GEN-LAST:event_lblReadReportMousePressed

    private void lblViewChartMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblViewChartMousePressed
        // TODO add your handling code here:
        DLChart chart = new DLChart(null, true);
        chart.setVisible(true);
    }//GEN-LAST:event_lblViewChartMousePressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbSource;
    private javax.swing.JLabel lbSource1;
    private javax.swing.JLabel lbSource2;
    private javax.swing.JLabel lblBoothMag;
    private javax.swing.JLabel lblReadReport;
    private javax.swing.JLabel lblViewChart;
    private javax.swing.JPanel pnDatenZone;
    private javax.swing.JPanel pnExhibi;
    private javax.swing.JPanel pnExhibi1;
    private javax.swing.JPanel pnExhibi2;
    private javax.swing.ButtonGroup rdGroupDate;
    // End of variables declaration//GEN-END:variables

}
